﻿@using System.Data;
@using UtilsCache;
@using GatewayServer.Common;
@using UtilsBase;
@{
    ViewBag.PageTitle = "洪峰智能";

    Layout = "~/Views/Shared/PageTemplate.cshtml";
}

<script>
    $(document).ready(function () {

        if ("@(ViewBag.order)" == "upd") {
            getEdit("@(ViewBag.m_guid)");
        }
        else {
            getModelTypeList();
            getAgreementList();
        }

    });


    function getEdit(dguid) {
        $.post("getModel", { "flag": Math.random(), guid: dguid }, function (result) {
            var myobj = (result.data);
            $("#m_name").val(myobj.m_name);
            $("#hid_m_type_guid").val(myobj.m_type_guid);
            
            $("#hid_m_agreement_guid").val(myobj.m_agreement_guid);
            $("#m_remark").val(myobj.m_remark);
            $("#m_value_remark").val(myobj.m_value_remark);
            

            $("#m_brand").val(myobj.m_brand);
            $("#m_parameter_demo").val(myobj.m_parameter_demo);
            $("#m_parameter_demo_init").val(myobj.m_parameter_demo_init);
            
            $("#m_command_explain").val(myobj.m_command_explain);
            for (var i = 0; i < document.getElementById("m_status").options.length; i++) {
                if (document.getElementById("m_status").options[i].value == myobj.m_status) {
                    document.getElementById("m_status").options[i].selected = true;
                    break;
                }
                else {
                    document.getElementById("m_status").options[i].selected = false;

                }
            }

            getModelTypeList();
            getAgreementList();
            getModelFileInfo(myobj.m_guid);
            getModelFileLogo(myobj.m_guid);
            getModelFile(myobj.m_guid);
        });
    }
    function getModelFileInfo(mguid) {
   //资料图片
        $.post("getModelFile", { "flag": Math.random(),"guid":mguid,"type":"info" }, function (result) {
            var fileurls = (result.data);
            document.getElementById("fileurl").value = fileurls;
            ShowFile("fileurl", "Div_showImg");
        });
    }
    function getModelFileLogo(mguid) {
        //logo图片
        $.post("getModelFile", { "flag": Math.random(), "guid": mguid, "type": "logo" }, function (result) {
            var fileurls = (result.data);
            document.getElementById("fileurlLogo").value = fileurls;
            ShowFile("fileurlLogo", "Div_showImgLogo");
        });
    }

    function getModelFile(mguid) {
        //文件
        $("#fileurlGuid").val(mguid);
        $.post("loadInfoFileTemp", { "flag": Math.random(), "guid": mguid, "type": "file" }, function (result) {
            var fileurls = (result.data);          
            showInfoFileTemp(mguid);//addfileV2.js
        });
    }
    function getAgreementList() {
        $("#m_agreement_guid").empty();
        $("#m_agreement_guid").append("<option value=''  selected='selected'>请选择</option>");
        $.post("getAgreementList", { "flag": Math.random() }, function (result) {
            var myobj = (result.data);
            for (var i = myobj.length - 1; i >= 0; i--) {
                $("#m_agreement_guid").prepend("<option value='" + myobj[i].a_guid + "'>" + myobj[i].a_name + "</option>")
            }
            for (var i = 0; i < document.getElementById("m_agreement_guid").options.length; i++) {
                if (document.getElementById("m_agreement_guid").options[i].value == $("#hid_m_agreement_guid").val()) {
                    document.getElementById("m_agreement_guid").options[i].selected = true;
                    break;
                }
                else {
                    document.getElementById("m_agreement_guid").options[i].selected = false;

                }
            }
        });
    }

    function getModelTypeList() {
        $("#m_type_guid").empty();
        $("#m_type_guid").append("<option value=''  selected='selected'>请选择</option>");
        $.post("getModelTypeList", { "flag": Math.random() }, function (result) {
            var myobj = (result.data);
            for (var i = myobj.length - 1; i >= 0; i--) {
                $("#m_type_guid").prepend("<option value='" + myobj[i].t_guid + "'>" + myobj[i].t_code + "-" + myobj[i].t_name + "</option>")
            }


            for (var i = 0; i < document.getElementById("m_type_guid").options.length; i++) {
                if (document.getElementById("m_type_guid").options[i].value == $("#hid_m_type_guid").val()) {
                    document.getElementById("m_type_guid").options[i].selected = true;
                    break;
                }
                else {
                    document.getElementById("m_type_guid").options[i].selected = false;

                }
            }
        });
    }


    function saveAll() {
        var data = $("#addForm").serializeArray(); //自动将form表单封装成json
        $.post("saveAll", data, function (result) {
            var jsonresult = (result);
            if (jsonresult.respCode == "200") {
                window.location.href = "list";
            }
            else {
                alert(jsonresult.respMsg);
                return;
            }
        });

    }
</script>

<style>
    #pagelist_follow {
        width: 100%;
    }

    #pagelist_main {
        width: 100%;
    }

    .kv-item label {
        width: 150px;
    }
</style>
<script src="~/js/addfile.js?322112222"></script>
<script src="~/js/addfileV2.js?3222112222"></script>
<div id="saper-container">
    <form id="addForm" name="addForm" action="list" method="post">
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>设备管理</h2>
            </div>
            <div class="subfiled-content">

                <div id="" title="添加/编辑">
                    <form action="" name="addForm" id="addForm" method="post">

                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>设备名称：</label>
                            <div class="kv-item-content">
                                <input type="text" name="m_name" id="m_name" placeholder="设备名称" />
                                <input type="hidden" name="m_guid" id="m_guid" value="@ViewBag.m_guid" />
                            </div>
                        </div>

                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>状态：</label>
                            <div class="kv-item-content">
                                <select id="m_status" name="m_status" style="width:130px;">
                                    <option value="0">启用</option>
                                    <option value="1">禁用</option>
                                </select>

                            </div>
                        </div>

                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>分类：</label>
                            <div class="kv-item-content">
                                <select id="m_type_guid" name="m_type_guid" style="width:130px;" onchange="checkShowGateWay(this.value)">
                                </select>
                                <input type="hidden" name="hid_m_type_guid" id="hid_m_type_guid" value="" />
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo"></span>品牌：</label>
                            <div class="kv-item-content">
                                <input type="text" name="m_brand" id="m_brand" placeholder="品牌" />
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo"></span>数据值备注：</label>
                            <div class="kv-item-content">
                            
                                <textarea id="m_value_remark" name="m_value_remark" cols="30" rows="10" style="width:420px;height:60px;"></textarea>


                            </div>
                        </div>
                        
                        <div class="kv-item clearfix">
                            <label><span class="impInfo"></span>协议：</label>
                            <div class="kv-item-content">
                                <select id="m_agreement_guid" name="m_agreement_guid" style="width:130px;">
                                </select>
                                <input type="hidden" name="hid_m_agreement_guid" id="hid_m_agreement_guid" value="" />
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo"></span>协议参数(json格式)：</label>
                            <div class="kv-item-content">

                                <textarea id="m_parameter_demo" name="m_parameter_demo" cols="30" rows="10" style="width:420px;height:100px;"></textarea>
                              
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo"></span>设备初始化(json格式)：</label>
                            <div class="kv-item-content">

                                <textarea id="m_parameter_demo_init" name="m_parameter_demo_init" cols="30" rows="10" style="width:420px;height:100px;"></textarea>
                                <br />
                                <a href="https://www.sojson.com/" target="_blank">json在线检测工具</a>
                                &nbsp;&nbsp;
                                <a href="https://jisuan5.com/hexadecimal-to-decimal/" target="_blank">进制转换</a>
                                &nbsp;&nbsp;
                                <a href="http://www.ip33.com/crc.html" target="_blank">modbus校验码</a>

                                
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo"></span>指令说明：</label>
                            <div class="kv-item-content">

                                <textarea id="m_command_explain" name="m_command_explain" cols="30" rows="10" style="width:420px;height:150px;"></textarea>
                             
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo"></span>备注：</label>
                            <div class="kv-item-content">
                                @* <input type="text" name="m_remark" id="m_remark" placeholder="备注" />*@

                                <textarea id="m_remark" name="m_remark" cols="30" rows="10" style="width:420px;height:60px;" placeholder="购买资料，商家信息"></textarea>

                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label ><span class="impInfo"></span>资料图片：</label>
                            <div class="kv-item-content">
                                <a href="javascript:;" class="aFile-upload" style="float:left">
                                    <span id="sp_img" style=""><img src="/common/images/addfile.png" style="vertical-align:middle" /></span>
                                    <input type="file" name="file_upload" id="file_upload" onchange="uploadChange(this,'file_upload_progress','fileurl','Div_showImg',20,0)" multiple="multiple">上传图片
                                </a>
                                <div style="float:right">
                                    <img src="" id="file_upload_progress" style="display: none; width: 25px; height: 25px; vertical-align: middle;" />
                                    <input type="hidden" id="fileurl" name="fileurl" value="" />
                                 </div>
                            </div>
                            <div id="Div_showImg"></div>
                        </div>

                        <div class="kv-item clearfix">
                            <label ><span class="impInfo"></span>LOGO：</label>
                            <div class="kv-item-content">
                                <a href="javascript:;" class="aFile-upload" style="float:left">
                                    <span id="sp_img" style=""><img src="/common/images/addfile.png" style="vertical-align:middle" /></span>
                                    <input type="file" name="file_uploadLogo" id="file_uploadLogo" onchange="uploadChange(this,'file_uploadLogo_progress','fileurlLogo','Div_showImgLogo',1,0)" multiple="multiple">上传图片
                                </a>
                                <div style="float:right">
                                    <img src="" id="file_uploadLogo_progress" style="display: none; width: 25px; height: 25px; vertical-align: middle;" />
                                    <input type="hidden" id="fileurlLogo" name="fileurlLogo" value="" />
                                </div>
                            </div>
                            <div id="Div_showImgLogo"></div>
                        </div>

                        <div class="kv-item clearfix">
                            <label><span class="impInfo"></span>资料文档：</label>
                            <div class="kv-item-content">
                                <a href="javascript:;" class="aFile-upload" style="float:left">
                                    <span id="sp_img" style=""><img src="/common/images/addfile.png" style="vertical-align:middle" /></span>
                                    <input type="file" name="file_uploadInfo" id="file_uploadInfo" onchange="uploadFile(this)" multiple="multiple">上传文件
                                </a>
                                <div style="float:right">
                                    <img src="" id="file_uploadInfo_progress" style="display: none; width: 25px; height: 25px; vertical-align: middle;" />
                                    <input type="hidden" id="fileurlGuid" name="fileurlGuid" value="" />

                                </div>
                            </div>
                            <div id="Div_showImgInfo" style="margin-left:300px;"></div>
                        </div>
                        <div><hr /></div>
                        <div style="margin:0 auto;width:150px;">

                            <input type="button" id="save" name="save" value="保存设备型号" onclick="javascript:saveAll()" />
                            &nbsp;&nbsp; <input type="button" id="but_back" name="but_back" value="返回" />
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div id="saper-ft"></div>
    </form>
</div>

